package com.woniu.order.controller;

import com.woniu.common.utils.PageData;
import com.woniu.common.utils.ResponseData;
import com.woniu.order.dto.ZcxApplicationDto;
import com.woniu.order.pojo.*;
import com.woniu.order.pojo.dto.ZcxCustomerOrderDTO;
import com.woniu.order.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class ZcxOrderController {

    @Autowired
    private ZcxCustomerOrderService zcxOrderService;

    @Autowired
    private ZcxOrderDetailsService zcxOrderDetailsService;

    @Autowired
    private CustomerService customerService;
    @Autowired
    private ZcxOrderApplicationProductService zcxOrderApplicationProductService;


    /**
     * 查询订单列表
     */
    @PostMapping("/queryOrderList")
    public ResponseData<?> queryOrderList(@RequestBody PageData<ZcxCustomerOrderDTO> pageData){
        return  zcxOrderService.queryList(pageData);
    }
    /** 订单修改页面
     * 根据订单code 查询订单
     */
    @GetMapping("/queryOrderById/{orderCode}")
    public ResponseData<?> queryOrderById(@PathVariable("orderCode") String orderCode){
        ZcxCustomerOrder order = zcxOrderService.lambdaQuery()
                .eq(ZcxCustomerOrder::getOrderCode, orderCode)
                .one();
        return  new ResponseData<>().ok(order);
    }

    /**订单修改页面
     * 根据订单code 查询订单
     */
    @GetMapping("/queryOrderDetailById/{orderCode}")
    public ResponseData<?> queryOrderDetailById(@PathVariable("orderCode") String orderCode){
//        List<ZcxOrderDetails> orderDetails = zcxOrderDetailsService.lambdaQuery()
//                .eq(ZcxOrderDetails::getOrderCode, orderCode)
//                .list();
//        return new ResponseData<>().ok(orderDetails);
        return  zcxOrderDetailsService.queryOrderDetailByCode(orderCode);
    }

    /**订单修改页面
     * 查询客户列表
     * @return
     */
    @PostMapping("/queryAllCustomer")
    public ResponseData<?> queryAllCustomer(){
        List<Customer> customers = customerService.lambdaQuery()
                .list();
        return new ResponseData<>().ok(customers);
    }

    /** 添加产品按钮 显示产品列表
     * 查询产品展示
     * @return
     */
    @GetMapping("/queryAllProduct")
    public ResponseData<?> queryAllProduct() {
        return zcxOrderService.queryAllProduct();
    }

    /**创建申请编号
     * @return
     */
    @GetMapping("/createSnowId")
    public ResponseData<?> createSnowId(){
        return zcxOrderService.createSnowId();
    }
    /**
     * 保存产品列表到申请表  ，往申请表塞数据
     */
    @PostMapping("/addApplication")
    public ResponseData<?> addApplication(@RequestBody ZcxApplicationDto zcxApplicationDto){
        return zcxOrderService.addApplication(zcxApplicationDto) ;
    }


    /**
     * 查询修改申请列表
     */
    @PostMapping("/queryOrderApplicationList")
    public ResponseData<?> queryOrderApplicationList(@RequestBody PageData<ZcxOrderApplication> pageData){
        return  zcxOrderService.queryOrderApplicationList(pageData);
    }

    /**
     * 根据applicationCode查询申请表数据
     * @return
     */
    @GetMapping("/queryOrderApplicationProduct/{applicationCode}")
    public ResponseData<?> queryOrderApplicationProduct(@PathVariable("applicationCode") String applicationCode) {
        return zcxOrderApplicationProductService.queryOrderApplicationProduct(applicationCode);
    }

    /**
     * 审批
     */
    @PostMapping("/approve")
    public ResponseData<?> approve(@RequestBody ZcxUpdateRecord zcxUpdateRecord){
        return  zcxOrderService.approve(zcxUpdateRecord);
    }

    /**
     * 结算
     */
    @PostMapping("/billing")
    public ResponseData<?> billing(){
        return  null;
    }



}
